//
//  ZM_ImgLblBtn_CVCell.m
//  YYFMMall
//
//  Created by chenzm on 2019/9/27.
//  Copyright © 2019 YuYou1. All rights reserved.
//

#import "ZM_ImgLblBtn_CVCell.h"

@implementation ZM_ImgLblBtn_CVCell{
    UIImage *img;
}

-(void)setImgV_size:(CGSize)imgV_size{
    _imgV_size = imgV_size;
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(imgV_size);
    }];
}

-(void)setImg_corner:(CGFloat)img_corner{
    _img_corner = img_corner;
    [ZMSpeedy zm_changeControl:self.imgV cornerRadius:img_corner borderWidth:0 borderColor:nil mask:YES];
}


-(void)btnAction:(UIButton *)sender{
    !self.deleteBtnBlock?:self.deleteBtnBlock();
}

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kWhiteColor;
        [self setBaseData];
        [self setUpUI];
    }
    return self;
}

-(void)setBaseData{
    img = kImage(@"icon_reduce_red");
}

- (void)setUpUI{
    [self imgV];
    [self deleteBtn];
    [self lbl];
}

#pragma mark - 布局
- (void)layoutSubviews{
    [super layoutSubviews];
}

#pragma mark - lazyLoad
-(UIImageView *)imgV{
    if (!_imgV) {
        _imgV = [[UIImageView alloc] init];
        _imgV.contentMode = UIViewContentModeScaleAspectFill;
        _imgV.clipsToBounds = YES;
        [self addSubview:_imgV];
        [_imgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self);
            make.centerX.mas_equalTo(self);
        }];
    }
    return _imgV;
}

-(UIButton *)deleteBtn{
    if (!_deleteBtn) {
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.titleLabel.font = kFont(13);
        [_deleteBtn setBackgroundImage:img forState:UIControlStateNormal];
        [_deleteBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_deleteBtn];
        BlockSelf(img);
        [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.imgV);
            make.left.mas_equalTo(self.imgV);
            make.size.mas_equalTo(blockimg.size);
        }];
    }
    return _deleteBtn;
}

-(UILabel *)lbl{
    if (!_lbl) {
        _lbl = [UILabel new];
        _lbl.font = kMediumFont(12);
        _lbl.textColor = kHexColor(0x999999);
        _lbl.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_lbl];
        [_lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.imgV.mas_bottom).offset(6);
            make.left.mas_equalTo(self).offset(5);
            make.right.mas_equalTo(self).offset(-5);
        }];
    }
    return _lbl;
}
@end
